/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package z.h.w.jar.kit.method;

import java.util.List;
import z.h.w.jar.arithmetic.Sort;
import z.h.w.jar.arithmetic.method.SortMethodApi;

/**
 *
 * @author EnzoZhong
 */
public class Num {

      public static Double 求反序数 ( Double... nums ) {
            Double sum = 0.0;
            List<Double> numList = To.array2List ( nums );
            List<Double> sortedList = Sort.sort ( To.array2List ( nums ) , SortMethodApi.SHELL );
            for ( Double num : sortedList ) {
                  Integer index = numList.indexOf ( num );
                  Integer tempNum = 0;
                  for ( Integer x = 0 ; x < index ; x ++ ) {
                        if ( numList.get ( x ) > num ) {
                              tempNum ++;
                        }
                  }
                  sum += tempNum;
                  numList.remove ( num );
            }
            return sum;
      }

      public static Integer 求反序数 ( Integer... nums ) {
            Double[] doubleArray = new Double[ nums.length ];
            for ( Integer x = 0 ; x < nums.length ; x ++ ) {
                  doubleArray[x] = nums[x].doubleValue ();
            }
            return 求反序数 ( doubleArray ).intValue ();
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Integer max ( Integer... nums ) {
            Integer max = nums[0];
            for ( Integer x = 0 ; x < nums.length ; x ++ ) {
                  max = Math.max ( nums[x] , max );
            }
            return max;
      }

      public static Boolean isInteger ( Double d ) {
            Integer partInteger = d.intValue ();
            return d - partInteger == 0.0 ? true : false;
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Long max ( Long... nums ) {
            Long max = nums[0];
            for ( Integer x = 0 ; x < nums.length ; x ++ ) {
                  max = Math.max ( nums[x] , max );
            }
            return max;
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Double max ( Double... nums ) {
            Double max = nums[0];
            for ( Integer x = 0 ; x < nums.length ; x ++ ) {
                  max = Math.max ( nums[x] , max );
            }
            return max;
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Integer min ( Integer... nums ) {
            Integer max = nums[0];
            for ( Integer x = 0 ; x < nums.length ; x ++ ) {
                  max = Math.min ( nums[x] , max );
            }
            return max;
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Long min ( Long... nums ) {
            Long max = nums[0];
            for ( Integer x = 0 ; x < nums.length ; x ++ ) {
                  max = Math.min ( nums[x] , max );
            }
            return max;
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Double min ( Double... nums ) {
            Double max = nums[0];
            for ( Integer x = 0 ; x < nums.length ; x ++ ) {
                  max = Math.min ( nums[x] , max );
            }
            return max;
      }

      /**
       *
       * @param nums
       * @param target
       *
       * @return
       */
      public static Boolean allEpuale ( Integer[] nums , Integer target ) {
            for ( int x = 0 ; x < nums.length ; x ++ ) {
                  if ( nums[x] != target ) {
                        return false;
                  }
            }
            return true;
      }

      /**
       *
       * @param matrix
       * @param row
       *
       * @return
       */
      public static Integer[] getRow ( Integer[][] matrix , Integer row ) {
            Integer[] re = new Integer[ matrix.length ];
            for ( int x = 0 ; x < matrix.length ; x ++ ) {
                  re[x] =
                  matrix[x][row];
            }
            return re;

      }

      /**
       *
       * @param matrix
       * @param column
       *
       * @return
       */
      public static Integer[] getColumn ( Integer[][] matrix , Integer column ) {
            return matrix[column];
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Integer sum ( Integer[] nums ) {
            Integer sum = 0;
            for ( int x = 0 ; x < nums.length ; x ++ ) {
                  sum += nums[x];
            }
            return sum;
      }

      public static Integer sum ( List<Integer> nums ) {
            Integer sum = 0;
            for ( int x = 0 ; x < nums.size () ; x ++ ) {
                  sum += nums.get ( x );
            }
            return sum;
      }

      /**
       *
       * @param nums
       *
       * @return
       */
      public static Double sum ( Double[] nums ) {
            Double sum = 0.0;
            for ( Double dou : nums ) {
                  sum += dou;
            }
            return sum;
      }

      /**
       *
       * @param minMax
       * @param num
       *
       * @return
       */
      public static Boolean inRang ( Integer[] minMax , Integer num ) {
            Integer[] sorted = Sort.sort ( minMax , SortMethodApi.SHELL );
            int len = sorted.length;
            int min = sorted[0];
            int max = sorted[len - 1];
            return min <= num && num <= max;
      }

      public static Number average ( List<Number> collection ) {
            Long total = 0L;
            Integer size = collection.size ();
            for ( Number num : collection ) {
                  total += num.longValue ();
            }
            return total / size;
      }

      public static Number average ( Number... nums ) {
            Long total = 0l;
            for ( Number num : nums ) {
                  total += num.longValue ();
            }
            return total / nums.length;
      }

      /**
       *
       * @param array
       *
       * @return
       */
      public static Integer average ( Integer[] array ) {
            Integer total = 0;
            Integer size = array.length;
            for ( int x = 0 ; x < size ; x ++ ) {
                  total += array[x];
            }
            return total / size;
      }

      public static Boolean in ( Integer min , Integer num , Integer max ) {
            return ( min <= num ) && ( num <= max );
      }

      public static Double 求斜边 ( Double 直角边1 , Double 直角边2 ) {
            直角边1 = 直角边1 * 直角边1;
            直角边2 = 直角边2 * 直角边2;
            return Math.sqrt ( 直角边1 + 直角边2 );
      }

}
